#include "tcpstatedialog.h"
#include "ui_tcpstatedialog.h"

TCPStateDialog::TCPStateDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::TCPStateDialog)
{
    ui->setupUi(this);

    init();
}

void TCPStateDialog::setState(QAbstractSocket::SocketState state)
{
    switch (state) {
    case QAbstractSocket::ConnectingState:
    {
        ui->okBtn->hide();
        break;
    }
    case QAbstractSocket::ConnectedState:{
        ui->okBtn->show();
        break;
    }
    case QAbstractSocket::UnconnectedState:{
        ui->okBtn->show();
        break;
    }
    case QAbstractSocket::ClosingState:{
        ui->okBtn->show();
        break;
    }
    default:{
         ui->stateLabel->setText("other state");
         ui->okBtn->hide();
    }
    }
}

void TCPStateDialog::setInfo(const QString &info)
{
    ui->stateLabel->setText(info);
}

TCPStateDialog::~TCPStateDialog()
{
    delete ui;
}

void TCPStateDialog::init()
{
    connect(ui->okBtn,&QPushButton::clicked,this,&TCPStateDialog::onOkBtnClicked);
}

void TCPStateDialog::onOkBtnClicked()
{
    this->accept();
}
